﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;

//有效的字母异位词
//https://leetcode.cn/problems/valid-anagram/
class Solution {
public:
    bool isAnagram(string s, string t) {
        if (s.size() != t.size()) return false;
        map<char, int> ms, mt;
        for (const auto& c : s) ++ms[c];
        for (const auto& c : t) ++mt[c];

        for (const auto& x : ms)
            if (!mt.count(x.first) || mt[x.first] != x.second)
                return false;

        return true;
    }
};

//判断字符串的两半是否相似
//https://leetcode.cn/problems/determine-if-string-halves-are-alike/description/
class Solution {
public:
    bool halvesAreAlike(string s) {
        char ch[] = { 'a','A','e','E','i','I','o','O','u','U' };
        set<char> setbit(ch, ch + 10);


        int n = s.size();
        int hal = (n - 1) / 2;

        int left = 0;   //左边的大小写字母数
        int right = hal + 1;  //右边的大小写字母数

        int count = 0;
        while (left >= 0 && right < n)
        {
            if (setbit.count(s[left++])) ++count;
            if (setbit.count(s[right++])) --count;
        }

        if (count == 0) return true;

        return false;
    }
};


